@echo off
setlocal enabledelayedexpansion

:: 设置Redis目录
set redis_catalogue=D:\Environment\Redis-x64-5.0.14.1
:: redis 密码
set redis_password=123456

:: redis配置文件路径
set config_path=D:\Environment\redisClusterCof

:: redis配置文件名
set redis_cof_name=redis.conf

:: 定义集群端口列表 整体路径：D:\Environment\redisClusterCof\8201\redis.conf
set ports=8201 8202 8203

:: 遍历启动所有Redis集群节点
echo Starting Redis Cluster Nodes...
for %%p in (%ports%) do (
    set config_file=%config_path%\%%p\%redis_cof_name%
    start "Redis Port %%p" cmd /k "%redis_catalogue%\redis-server.exe !config_file!"
    timeout /t 1 /nobreak >nul
)
:: 等待所有节点启动完成
timeout /t 2 /nobreak >nul

:: 启动集群
:: redis-cli --cluster create --cluster-replicas 0 127.0.0.1:8201 127.0.0.1:8202 127.0.0.1:8203
start "Redis CLI" cmd /c "%redis_catalogue%\redis-cli.exe  -a %redis_password% --cluster create --cluster-replicas 0 127.0.0.1:8201 127.0.0.1:8202 127.0.0.1:8203 --cluster-yes"

:: timeout /t 3 /nobreak >nul

:: 启动Redis CLI 如果没有就算了
:: start "Redis CLI" cmd /c "%redis_catalogue%\redis-cli.exe" -c -p 8201 -a %redis_password%